package com.university.mentalhealthplatform.studentV3.service;

import com.university.mentalhealthplatform.appModels.Message;
import com.university.mentalhealthplatform.appModels.Reply;
import com.university.mentalhealthplatform.studentV3.repository.MessageRepositoryV3;
import com.university.mentalhealthplatform.studentV3.repository.ReplyRepositoryV3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class MessageServiceV3 {

    @Autowired
    private MessageRepositoryV3 messageRepositoryV3;

    @Autowired
    private ReplyRepositoryV3 replyRepositoryV3;

    // 保存新的留言
    public Message saveMessage(Message message) {
        return messageRepositoryV3.save(message);
    }

    // 根据学生ID获取留言
    public List<Message> getMessagesByStudentId(UUID studentId) {
        return messageRepositoryV3.findByStudentId(studentId);
    }

    // 回复留言
    public Reply replyToMessage(Long messageId, Reply reply) {
        Message message = messageRepositoryV3.findById(messageId).orElseThrow(() -> new RuntimeException("留言未找到"));
        reply.setMessage(message);
        return replyRepositoryV3.save(reply);
    }

    // 获取所有留言
    public List<Message> getAllMessages() {
        return messageRepositoryV3.findAll();
    }


}

